package com.chkj.fbook.common.utils;

import java.security.MessageDigest;

import org.apache.shiro.crypto.hash.Sha256Hash;

public class MD5Utils {
	
	public static final String SALT_KEY = "akoaix";
	
	/**
	 * md5加密方式
	 */
	public static String md5(String str) {
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(str.getBytes("UTF-8"));
			byte[] encryption = md5.digest();
			StringBuffer strBuf = new StringBuffer();
			for (int i = 0; i < encryption.length; i++) {
				if (Integer.toHexString(0xff & encryption[i]).length() == 1) {
					strBuf.append("0").append(Integer.toHexString(0xff & encryption[i]));
				} else {
					strBuf.append(Integer.toHexString(0xff & encryption[i]));
				}
			}
			return strBuf.toString();
		} catch (Exception e) {
			return "";
		}
	}
	
	/**
	 * 密码加密
	 */
	public static String encryptPassword(String password) {
		password = md5(password);
		Sha256Hash hash = new Sha256Hash(String.valueOf(password),SALT_KEY);
		return hash.toBase64();

	}
	public static void main(String[] args) {
		//System.out.println(MD5Utils.encryptPassword(md5("111111")));
	}

}
